package xyz.zq.validation.annotation;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import xyz.zq.validation.service.MyValidService;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

@Slf4j
@AllArgsConstructor
public class MyConstraintValidator implements ConstraintValidator<MyValid, Object> {

    private final MyValidService myValidService;

    @Override
    public void initialize(MyValid constraintAnnotation) {
        log.info("initialize MyConstraintValidator");
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
            log.info(value.toString());
        return myValidService.valid(value);
    }
}
